package com.turing.post.cardmanagement.impl;

import java.math.BigInteger;
import java.util.List;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.turing.post.cardmanagement.util.AppCardFaceAssoc;
import com.turing.post.cardmanagement.util.AppCardFaceAssocDao;
import com.turing.post.util.GeneralDao;
import com.turing.post.util.PCPSApplicationException;

@Stateless(mappedName = "cardmanagement.impl.AppCardFaceAssocDaoImpl")
@Remote
@Local
public class AppCardFaceAssocDaoImpl implements AppCardFaceAssocDao {

	/**
	 * 实体管理器
	 * 
	 * @see javax.persistence.EntityManager
	 */
	@PersistenceContext
	protected EntityManager _em;

	@Override
	public AppCardFaceAssoc getAppCardFaceAssoc(AppCardFaceAssoc acfa) {
		return _em.find(AppCardFaceAssoc.class, acfa);
	}

	@Override
	public void insert(AppCardFaceAssoc acfa) throws PCPSApplicationException {
		GeneralDao.insert(_em, acfa);
	}

	@Override
	public void update(AppCardFaceAssoc acfa) throws PCPSApplicationException {
		GeneralDao.update(_em, acfa);
	}

	@Override
	public void remove(BigInteger cardFaceId) throws PCPSApplicationException {
		String sql = "delete from AppCardFaceAssoc ac where ac.Cardfaceid=?1";
		Query query = _em.createNativeQuery(sql);
		query.setParameter(1, cardFaceId);
		query.executeUpdate();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AppCardFaceAssoc> getAppCardFaceAssocByCardId(String cardFaceId) {
		String sql = "select * from AppCardFaceAssoc acfa where acfa.Cardfaceid=?1";
		Query query = _em.createNativeQuery(sql, AppCardFaceAssoc.class);
		query.setParameter(1, cardFaceId);
		List<AppCardFaceAssoc> list = query.getResultList();
		if (list != null && list.size() > 0)
			return list;
		return null;
	}
}
